assume  cs:code, ss:stk
public	rand
RTC      equ     es:[6ch]

stk	segment stack
	db	32 dup (?)	; allocate 32 bytes for stack
tos	label	word		; alignment by word
stk	ends

code 	segment

;==========================================================================
;                               Procedures
;=========================================================================={{

;--------------------------------------------------------------------------
; Saves random number from 1-6 to AX. DOES NOT PRINT IT.
;--------------------------------------------------------------------------{{{	


proc	rand	far

	PUSH	BX
	PUSH	CX
	PUSH	DX
	PUSH 	ES
	
	MOV	AX, 40h
	MOV	ES, AX
again:  	mov	ax, RTC		;saves current RTC value into ax
	and	al, 07h		;retrieve 0-255
	mov	ah, 00h

	cmp	al, 07h		;if value is 255,roll dice again
	je	again

	cmp	al,00h		;if value is 0, roll dice again
	je	again
	
	mov	ah,00		;Now AX contains a single random number.

	POP	ES
	POP	DX		;retrieve the registers
	POP	CX
	POP	BX
		
	ret

rand	endp		

code    ends
end
